package com.yuqiang.common.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * Created by Administrator on 2016/5/21 0021.
 */
public class DateGetUtil {


    //获取今天
    public static String getToday(){
        Date today = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String todayString = formatter.format(today);
        return todayString;
    }
    //获取明天
    public static String getTomorrow(){
        Date today = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(today);
        calendar.add(calendar.DATE,1);//把日期往后增加一天.整数往后推,负数往前移动
        today=calendar.getTime(); //这个时间就是日期往后推一天的结果
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String tomorrowString = formatter.format(today);
        return tomorrowString;
    }
    //获取其他时间
    public static String getOtherDay(int i){
        Date today = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(today);
        calendar.add(calendar.DATE,i);//整数往后推,负数往前移动
        today=calendar.getTime(); //这个时间就是日期往后推一天的结果
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String todayString = formatter.format(today);
        return todayString;
    }

    //获取当前时间精确到毫秒
    public static String getKeyTime(){
        String key = new SimpleDateFormat("yyyyMMddHHmmssSSS") .format(new Date() );
        return key;
    }
}
